package kodkod.analysis.visitor;

import java.util.HashMap;

import kodkod.ast.Formula;
import kodkod.ast.LeafExpression;
import kodkod.ast.Node;

public class MinimumDistance extends AbstractAnalyzer {
	
	public HashMap<Node, Integer> distance = new HashMap<Node, Integer>();
	
	public MinimumDistance(Formula formula) {
		this.visit(formula);
	}
	
	@Override
	public void beginChild(Node e1, Node e2) {
		Integer w1 = distance.get(e1);
		Integer w2 = distance.get(e2);
		if (w1 == null) {
			distance.put(e1, 0);
			distance.put(e2, 1);
		}
		else if (w2 == null) {
			distance.put(e2, w1+1);
		}
		else if (w1+1 < w2) {
			distance.put(e2, w1+1);
		}
	}
	
	@Override
	void endChild(Node parent, Node child) {}

	@Override
	boolean visited(Node node) {
		return false;
	}

	@Override
	void foundLeafExpression(LeafExpression leaf) {}
}
